package me.numark.view;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import java.util.List;

import me.numark.R;
import me.numark.model.Like;
import me.numark.model.User;

/**
 * Created by Evan on 15/7/24.
 */
public class UserGridAdapter extends UltimateViewAdapter<UserGridViewHolder> {

    List<Like> dataList;
    Object mParent;

    public UserGridAdapter(List<Like> dataList, Object parent) {
        this.dataList = dataList;
        mParent = parent;
    }


    @Override
    public UserGridViewHolder getViewHolder(View view) {
        return new UserGridViewHolder(view, mParent, UserGridViewHolder.STYLE_NONE);
    }

    @Override
    public UserGridViewHolder onCreateViewHolder(ViewGroup parent) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.user_grid_item, parent, false);
        UserGridViewHolder vh = new UserGridViewHolder(v, mParent, UserGridViewHolder.STYLE_NORMAL);
        return vh;
    }

    @Override
    public int getAdapterItemCount() {
        return dataList.size();
    }

    @Override
    public long generateHeaderId(int i) {
        return 0;
    }

    @Override
    public void onBindViewHolder(UserGridViewHolder holder, int position) {
        if (position < dataList.size()) {
            Like like = dataList.get(position);
            holder.bindData(like);
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup viewGroup) {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewHolder, int i) {

    }

    public void append(Like item) {
        insert(dataList, item, dataList.size());
    }

    public void append(Like[] items) {
        int pos = dataList.size();
        for (Like item : items) {
            if (!dataList.contains(item))
                dataList.add(item);
        }
        notifyItemRangeInserted(pos, items.length);
    }

    public void remove(int position) {
        remove(dataList, position);
    }

    public void clear() {
        clear(dataList);
    }

}
